import re
from playwright.sync_api import Playwright, sync_playwright, expect


def run(playwright: Playwright) -> None:
    browser = playwright.chromium.launch(headless=False)
    context = browser.new_context(viewport={"width":1920,"height":1080})
    page = context.new_page()
    page.goto("http://localhost:8080/user/login")
    page.locator("div").filter(has_text="Himool ERP盒木进销存管理系统公司编号用户名密码登 录注册账号试用，购买或问题咨询请扫描下方客户经理二维码").nth(1).click()
    page.get_by_role("textbox").first.click()
    page.get_by_role("textbox").first.fill("001")
    page.get_by_role("textbox").first.press("Tab")
    page.get_by_role("textbox").nth(1).fill("admin")
    page.get_by_role("textbox").nth(1).press("Tab")
    page.locator("input[type=\"password\"]").fill("admin")
    page.locator("input[type=\"password\"]").press("Enter")
    page.locator("div").filter(has_text=re.compile(r"^基础数据$")).click()
    page.get_by_role("menuitem", name="客户管理").click()
    page.get_by_role("button", name="图标: plus 新增客户").click()
    page.locator(".ant-form-item-children > .ant-input").first.click()
    page.locator(".ant-form-item-children > .ant-input").first.fill("test002")
    page.get_by_role("button", name="确 定").click()

    # ---------------------
    context.close()
    browser.close()


with sync_playwright() as playwright:
    run(playwright)
